import React from 'react';
import { connect } from 'dva';
import DocumentTitle from 'react-document-title';
import { Redirect, Route, Switch } from 'dva/router';
import { getRoutes } from '../utils/utils';
import  HomePage  from '../routes/homepage/homePage';

class BasicLayout extends React.PureComponent {
  getPageTitle() {
    const { routerData, location } = this.props;
    const { pathname } = location;
    let title = 'Ant Design Pro';
    if (routerData[pathname] && routerData[pathname].name) {
      title = `${routerData[pathname].name} - 绩 效 系 统`;
    }
    return title;
  }
  render() {
    const { routerData, match, isFetch, isShow } = this.props;
    const layout = (
      <Switch>
        {
          getRoutes(match.path, routerData).map(item =>
            (
              <Route
                key={item.key}
                path={item.path}
                component={item.component}
                exact={item.exact}
              />
            )
          )
        }
        <Redirect exact from="/" to="/classify" />
      </Switch>
    );
    return (
    <div>
      <DocumentTitle title={this.getPageTitle()} >
        <div>
          {
            isFetch ? layout : null
          }
        </div>
         
      </DocumentTitle>
      <div >
      {
        isShow ?  <HomePage />  : null
      }
      </div>
    </div>
    );
  }
}

export default connect(({ global }) => ({
  isFetch: global.isFetch,
  isShow: global.isShow,
}))(BasicLayout);
